﻿using DoNetDrive.Core.Packet;
using DotNetty.Buffers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Face8280WebSocketServer.Command
{
    public class TextPacket : INPacket
    {
        public static Encoding JsonEncoding = Encoding.UTF8;

        private string JsonString;
        public TextPacket(string jString)
        {
            JsonString=jString;
        }
        public void Dispose()
        {
           
        }
        public string GetJson()
        {
            return JsonString;
        }

        public IByteBuffer GetPacketData(IByteBufferAllocator Allocator)
        {         
            var iCount = JsonEncoding.GetByteCount(JsonString);         
            var buf = Allocator.Buffer(iCount);
            buf.WriteBytes(JsonEncoding.GetBytes(JsonString));
            return buf;
        }

        public void ReleaseDataBuf()
        {
            
        }
    }
}
